#pragma once
#include "Global.h"
#include "DefineCol.h"
#include <functional>
#include <ctime>
#include <string>
using namespace std;
class CEventManager;
class CSymbolInfo;
class CAccountInfo;
class CPositionInfo;
class CChartMultiData;
class COrderInfo;
class CGomOrderManager;

class CSysUnit
{
public:
	CSysUnit();
	CSysUnit(string name);
	virtual ~CSysUnit();

	CGomOrderManager* m_GomOrderMgr;
	CEventManager* m_pEventMgr;
	CSymbolInfo* m_CurSymbol;
	CAccountInfo* m_CurAccount;
	CPositionInfo* m_CurPosition;
	int BaseOrderAmount() const { return m_BaseOrderAmount; }
	void BaseOrderAmount(int val) { m_BaseOrderAmount = val; }
	HMODULE		hIns;
	bool m_EnableLossCut;
	bool m_EnableProfitCut;
	long m_LossCutVal;
	long m_ProfitCutVal;

	CChartMultiData* MainData() const { return m_MainData; }
	void MainData(CChartMultiData* val) { m_MainData = val; }
	SignalList* GetSignalList()
	{
		return &m_SigList;
	}
	string SysName;
	bool RealTime;
protected:
	CChartMultiData* m_MainData;
	int     m_BaseOrderAmount;
	CondVec m_EntryCondList;
	CondVec m_ExitCondList;
	SignalList m_SigList;

public:

	virtual bool Run() = 0;
	virtual bool Run(int a_Index) = 0;

	void AddEntryCondition(CCondUnit* a_Cond);
	void AddExitCondition(CCondUnit* a_Cond);

	double SumCondition(CondType a_CondType);
	void CheckEntrySignal();
	void CheckLPCut();
	virtual bool CheckEnter(int a_Index) = 0;
	virtual bool CheckLossCut(int a_Index) = 0;
	virtual bool CheckProfitCut(int a_Index) = 0;
	MarketPositionType GetMarketPosition();
	MarketPositionType GetTodayMarketPosition();
	int GetTodaySignalCount();
	int GetDaySignalCount(int a_Index);
	
	CSignal* AddSignal(int a_Index, SigType a_SigType);
	CSignal* AddSignal(int a_Index, SigType a_SigType, double a_Price);

	COrderInfo* PutEntryOrder(CSignal* a_Sig);
	COrderInfo* PutLossCutOrder(CSignal* a_Sig);
	COrderInfo* PutProfitCutOrder(CSignal* a_Sig);

	void MakeOrderParam(OrderReqParam& a_Param, CSignal* a_Sig);
	void SendOrder(OrderReqParam& a_Param);
};

